package com.fanyouzhao.ehome.service.impl;

import com.fanyouzhao.ehome.dao.CpDao;
import com.fanyouzhao.ehome.dao.impl.CpDaoImpl;
import com.fanyouzhao.ehome.entity.Cp;
import com.fanyouzhao.ehome.service.CpService;

import java.util.List;

/**
 * @Author: fanyouzhao
 * @Date: 10:18 2021/5/10
 */
public class CpServiceImpl implements CpService {

    CpDao cpDao = new CpDaoImpl();

    @Override
    public List<Cp> selectAll() throws Exception {
        return cpDao.selectAll();
    }

    @Override
    public List<Cp> selectByPage(Integer page, Integer size) throws Exception {
        return cpDao.selectBypage(page,size);
    }

    @Override
    public Cp selectById(Integer id) throws Exception {
        return cpDao.selectById(id);
    }

    @Override
    public Boolean insert(Cp cp) throws Exception {
        Integer insert = cpDao.insert(cp);
        if (insert>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean update(Integer id, Cp cp) throws Exception {
        Cp selectCp = cpDao.selectById(id);
        if (selectCp!=null) {
            Integer update = cpDao.update(id, cp);
            if (update>0){
                return true;
            }else{
                return false;
            }
        } else {
            return false;
        }
    }

    @Override
    public Boolean deleteById(Integer id) throws Exception {
        Cp selectCp = cpDao.selectById(id);
        if (selectCp!=null) {
            Integer del = cpDao.deleteById(id);
            if (del>0){
                return true;
            }else{
                return false;
            }
        } else {
            return false;
        }
    }

    @Override
    public Integer getCount() throws Exception {
        return cpDao.getCount();
    }

}
